package com.ganbo.thread;

/**
 * Created by gan on 2020/5/18 23:48.
 */
public class SleepDemo extends Thread {

    private Object lock = new Object();

    @Override
    public void run() {

        synchronized (lock) {
            System.out.println(Thread.currentThread().getName() + "执行睡眠前");
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "执行睡眠后");
        }
    }

    public static void main(String[] args) {
        SleepDemo sleepDemo = new SleepDemo();

        Thread t1 = new Thread(sleepDemo, "t1");
        Thread t2 = new Thread(sleepDemo, "t2");

        t1.start();
        t2.start();
    }
}
